package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理项目控制层
 * @Description NursingProjectController
 * @Author hu hanSan
 * @Date 2024-09-06
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController{
    @Autowired
    private NursingProjectService nursingProjectService;
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称") String name,
            @ApiParam(value = "状态0，1")Integer status,
            @ApiParam(value = "页码")@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")@RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize){

        PageResponse<NursingProjectVo>info= nursingProjectService.getByPage(name,status,pageNum,pageSize);
        return success(info);
    }

    /**
     * 新增护理项目
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增护理项目",notes ="根据传入的id" )
    public ResponseResult insert(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.insertNursingProject(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "跟id来查询护理项目",notes = "传进来的id")
    public ResponseResult<NursingProjectVo> selectById(@PathVariable Long id){
       NursingProjectVo nursingProjectVo = nursingProjectService.findNursingProjectById(id);
        return success(nursingProjectVo);
    }
    @PutMapping
    @ApiOperation(value = "修改护理项目")
    public ResponseResult<NursingProjectVo> updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    public ResponseResult update(@PathVariable Long id, @PathVariable Integer status){
        nursingProjectService.update(id,status);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理项目",notes = "传进来的id")
    public ResponseResult delete(@PathVariable Long id){
        nursingProjectService.delete(id);
        return success();
    }
    @GetMapping("/all")
    public ResponseResult<List<NursingProjectVo>> selectAll(){
        List<NursingProjectVo>list= nursingProjectService.selectAll();
        return success(list);
    }
}
